#include "enemyplane.h"
#include "config.h"

EnemyPlane::EnemyPlane()
{
    // 敌机资源加载
    m_enemy.load(ENEMY_PATH);
    // 敌机位置
    m_x = 0;
    m_y = 0;
    // 敌机状态
    m_free = true;
    // 敌机速度
    m_speed = ENEMY_SPEED;
    // 敌机矩形框
    m_rect.setWidth(m_enemy.width());
    m_rect.setHeight(m_enemy.height());
    m_rect.moveTo(m_x, m_y);
}

void EnemyPlane::updatePosition()
{
    // 空闲状态
    if (m_free)
    {
        return;
    }
    m_y += m_speed;
    m_rect.moveTo(m_x, m_y);
    // 超出屏幕，重置空闲状态
    if (m_y >= GAME_HEIGHT + m_rect.height())
    {
        m_free = true;
    }
}
